﻿// JavaScript Document
$.moonbox = {
	opacity		: 0.7,//层遮罩透明度
	overlay		: true,
	bgColor		: "#000",//层遮罩颜色
	loadingImage: '/JS/MsgBox/preload.gif',
	title		: '',
	content		: '',
	topHtml		: '<div id="top"></div>',
	contentHtml	: '<div id="content"></div>',
	footerHtml	: '<div id="footer"><input type="submit" value="提 交" /><input type="button" value="取消" onclick="$.moonbox.close()" /></div>',
	moonboxHtml	: '\
	<div id="moonbox" style="display:none">\
		<div class="popup">\
			<table>\
				<tbody>\
					<tr>\
						<td class="tl" /><td class="tm" /><td class="tr" />\
					</tr>\
					<tr>\
						<td class="lm" />\
						<td class="body">\
						    <div class="loading"><img src="/JS/MsgBox/preload.gif" /></div>\
						</td>\
						<td class="rm" />\
					</tr>\
					<tr>\
						<td class="bl" /><td class="bm" /><td class="br" />\
					</tr>\
				</tbody>\
			</table>\
		</div>\
	</div>',
	show	: function(){
	    $('#moonbox').fadeIn();
		$('#moonbox').css('left', $(window).width() / 2 - ($('#moonbox table').width() / 2));
		$('#moonbox').css('top', $(window).height() / 2 - ($('#moonbox table').height() / 2-$(window).scrollTop()));
		$('#moonbox .loading').remove();
		$('#moonbox .close').click($.moonbox.close);
	},
	dialog		: function(){
		if($("#moonbox")) $("#moonbox").remove();
		$('body').append($.moonbox.moonboxHtml);
		$('#moonbox').fadeIn();
		$('#moonbox').css('left', $(window).width() / 2 - ($('#moonbox table').width() / 2));
		$('#moonbox').css('top', $(window).height() / 2 - ($('#moonbox table').height() / 2-$(window).scrollTop()));
		showOverlay();
		},
	loadAjax	: function(href) {
		$.moonbox.dialog();
		fillFromAjax(href);
	},
	loadNewAjax	: function(href) {
		$.moonbox.dialog();
		fillFromAjax(href+"?random="+Math.random());
	},
	loading		: function() {
	    $.moonbox.dialog();
	},
	ok	: function(content) {
		$.moonbox.dialog();
		$('.body').append($.moonbox.contentHtml);
		$('#content').css("padding","20px 15px 20px 55px").addClass('mbox_ok');
		$('#content').append(content?content:'&nbsp;');
		$.moonbox.show();
		setTimeout($.moonbox.close,1500);
	},
	error	: function(content) {
		$.moonbox.dialog();
		$('.body').append($.moonbox.contentHtml);
		$('#content').css("padding","20px 15px 20px 55px").addClass('mbox_err');
		$('#content').append(content?content:'&nbsp;');
		$.moonbox.show();
		setTimeout($.moonbox.close,1500);
	},
	warning	: function(content) {
		$.moonbox.dialog();
		$('.body').append($.moonbox.contentHtml);
		$('#content').css("padding","20px 15px 20px 55px").addClass('mbox_war');
		$('#content').append(content?content:'&nbsp;');
		$.moonbox.show();
		setTimeout($.moonbox.close,1500);
		$('#moonbox .loading').remove();
	},
	otherShow: function(){
		$("select").show();
		$("object").show();
	},
	otherHide: function(){
		$("select").hide();
		$("object").hide();
	},
	close	: function() {
      $("#moonbox").fadeOut();
	  hideOverlay();
	  if(isIE6()){$.moonbox.otherShow();}
      return false
    },
    reveal: function(data) {
      $('#moonbox .body').append(decodeURI(data));
      $.moonbox.show();
    }
}

function skipOverlay() {
    return $.moonbox.overlay == false || $.moonbox.opacity === null 
}

function fillFromAjax(href) {
    $.get(href, function(data) {$.moonbox.reveal(data); })
}

function showOverlay() {
	if (skipOverlay()) return
	var wnd = $(window), doc = $(document);
	if(wnd.height() > doc.height()){wHeight = wnd.height();}
	else{wHeight = doc.height();}
	if ($('moonbox_overlay').length == 0) 
	  $("body").append('<div id="moonbox_overlay" class="moonbox_hide"></div>')
	  $('#moonbox_overlay').hide()
	  .css({background: $.moonbox.bgColor,zIndex: "99",opacity:$.moonbox.opacity,filter:"Alpha(opacity="+$.moonbox.opacity*100+");",display:"block",position:"absolute"})
	  .fadeIn(200);
	  $("body").find("#moonbox_overlay").width(wnd.width()).height(wHeight);
	  if(isIE6()){$.moonbox.otherHide();}
	return false
}

function hideOverlay() {
	if (skipOverlay()) return
	$('#moonbox_overlay').fadeOut(200, function(){
	  $("#moonbox_overlay").addClass("moonbox_hide") 
	  $("#moonbox_overlay").remove()
	})
	return false
}

function isIE6(){
	var browser=navigator.appName;
	var b_version=navigator.appVersion;
	var version=b_version.split(";"); 
	var trim_Version=version[1].replace(/[ ]/g,""); 
	if(browser=="Microsoft Internet Explorer" && trim_Version=="MSIE6.0") { 
		return true;
	}
	return false;
}